#pragma once
#include "mfcore.hpp"

typedef struct AutoPlayStruct{
    SDL_Rect rect;//遮挡用
    int w,h;//当前
}AutoPlayStruct;

//暂停请SetEnable(false)
class AutoPlayText:public Control{
    static void AutoPlay(void*);
    static void AutoPlayFast(void*);
    //文字->遮挡   点击->回调->处理对象调用代码和分发剧情文本->返回->执行
    vector<AutoPlayStruct> cache;
    vector<AutoPlayStruct>::iterator pos;
    void* arg;
    void(*callback)(void*);//点击时触发
    Task* task;//自动播放task
    SDL_Texture*_t,*back;
    bool is_fast;
    public:
    vector<TextMod> _cache;//由SetText设置
    SDL_Texture* Background();
    bool Finish();
    bool IsFast();
    void Play();
    void PlayFast();
    void Stop();
    void SetCallback(void(*)(void*),void* a);
    void SetText(const initializer_list<TextMod>& text);
    void SetText(const vector<TextMod>& text);
    void SetAlpha(unsigned char a);
    unsigned char Alpha();
    //默认透明度0
    AutoPlayText(Window* win,SDL_Rect& r,const char* back_path,void(*callback)(void*),void* arg);
    ~AutoPlayText();
    void _draw();
    void _release(int x,int y,int clicks,unsigned char key);
};